import React, { Component } from 'react';
import { Redirect } from "react-router-dom"
import storageUtils from "../../utils/storageUtils"
import "./Admin.less"
import { Layout } from 'antd';
import LeftNav from "../../components/leftnav/LeftNav"
import {Switch , Route} from "react-router-dom"
import Home from "./home/Home"
import Category from "./category/Category"
import Product from "./products/Product"
import User from "./user/User"
import Role from "./role/Role"
import Bar from "./charts/Bar"
import Line from "./charts/Line"
import Pie from "./charts/Pie"
import Header from "../../components/header/Header"

const {Footer, Sider, Content } = Layout;

class admin extends Component {

    render() {
        const user = storageUtils.getUser();
        if (!user._id) {
            return <Redirect to="/login"></Redirect>
        }

        return (
            <div className="adminbox">
                <Layout style={{"height":"100%"}}>
                    <Sider>
                        <LeftNav></LeftNav>
                    </Sider>
                    <Layout>
                        <Header/>
                        <Content style={{background:"#fff",margin:15,minHeight:"auto"}}>
                            <Switch>
                                <Route path="/admin/home" component={Home}></Route>
                                <Route path="/admin/category" component={Category}></Route>
                                <Route path="/admin/product"  component={Product}></Route>
                                <Route path="/admin/user" component={User}></Route>
                                <Route path="/admin/role" component={Role}></Route>
                                <Route path="/admin/charts/bar" component={Bar}></Route>
                                <Route path="/admin/charts/line" component={Line}></Route>
                                <Route path="/admin/charts/pie" component={Pie}></Route>
                                <Redirect to="/admin/home"></Redirect>
                            </Switch>
                        </Content>
                        <Footer className="footer" style={{background:"rgb(255,255,255)"}}>
                            <h1>欢迎来到后台管理系统</h1>
                        </Footer>
                    </Layout>
                </Layout>
            </div>
        );
    }
}

export default admin;